package com.cat.dynamicPlanning;

import java.util.Arrays;
import java.util.Map;

/**
*   @description https://leetcode.cn/problems/delete-and-earn/
*   @author 曲大人的喵
*   @create 2025/8/27 17:13
*   @since JDK17
*/

public class Solution14 {
    public int f(int []arr) {
        int f = arr[0], s = Math.max(f, arr[1]);
        for (int i = 2, t; i < arr.length; i++) {
            t = s;
            s = Math.max(f + arr[i], s);
            f = t;
        }
        return Math.max(f, s);
    }

    public int deleteAndEarn(int[] nums) {
        int n = nums.length, max = Arrays.stream(nums).max().getAsInt();
        int[] arr = new int[max + 1];
        for (var x : nums) {
            arr[x] += x;
        }
        return f(arr);
    }
}
